/**
 * 判断链表中是否有环
 * 快慢指针解法
 * @param {ListNode} head 
 */
var hasCycle = function (head) {
    if (head === null) {
        return false
    }
    // 定义快慢指针
    let slow = head
    let fast = head
    while (fast.next !== null && fast.next.next !== null) {
        slow = slow.next
        fast = fast.next.next
        if (slow === fast) {
            return true
        }
    }

    // 跳出循环说明fast.next为空，肯定没有环
    return false
}